/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package easybooking.clients.gui;

import easybooking.FlightManagement;
import easybooking.data.Airline;
import easybooking.data.Airport;
import easybooking.data.Booking;
import easybooking.data.Customer;
import easybooking.data.Plane;
import easybooking.data.Type;
import easybooking.data.Seat;
import easybooking.data.Flight;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.*;

/**
 * In this Java class Client-Requests are realized as operations.
 * @author Tim Schröder
 * @author Hakan Keles
 * @author Bernd Opitz
 */
public class EBInterfaceClient {

    FlightManagement management = null;
    private String hostname;

    public EBInterfaceClient() {
    }

    /**
     * Initialises the conenction to the remote-Object "FlightManagement1" by looking up the RMI-Registry
     * @param hostname
     * @return a boolean determining if the connection was successfull
     */
    public boolean initServerConnection(String hostname) {
        this.hostname = hostname;
        String rmiRegistryServer = System.getProperty("java.rmi.registry.hostname", this.hostname);
        try {
            // Zunächst benötigen wir eine Verbindung mit einem Flight Management.
            management = (FlightManagement) Naming.lookup("rmi://" + rmiRegistryServer + ":1099/FlightManagement1");

            /*
             * Wenn wir hier ankommen, dann besteht eine Verbinung zum Server.
             * Wäre die Verbindung nicht zustande gekommen, so wäre eine
             * Exception ausgeworfen worden und das Programm wäre in den
             * entsprechenden Catch-Block (s.u.) gesprungen.
             */
            System.out.println("Verbindung hergestellt...");


        } catch (MalformedURLException murle) {
            System.out.println("MalformedURLException");
            System.out.println(murle);
            return false;
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);
            return false;
        } catch (NotBoundException e) {
            System.out.println("NotBoundException");
            System.out.println(e);
            return false;
        }
        return true;
    }

    /**
     * Gets all customers from the management object
     * @return A vector containing customers.
     */
    public Vector<Customer> getAllCustomers() {
        Vector v = new Vector();
        try {
            v = management.getAllCustomers();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Creates a new Customer Object
     * @param firstName The firstname of the created customer
     * @param lastName The lastname of the created customer
     * @param street The street of the created customer
     * @param zip The zip code of the created customer
     * @param city The city of the created customer
     */
    public void createCustomer(String firstName, String lastName, String street, String zip, String city) {
        Customer c = null;

        if (management == null) {
            initServerConnection(hostname);
        }

        try {
            c = management.createCustomer(firstName, lastName, street, Integer.valueOf(zip), city);

            if (c != null) {

                System.out.println("Neuer Kunde: " + "Kunden.-ID.: " + c.getCustomerId() + ", " + c.getLastname() + ", " + c.getFirstname() + ", " + c.getStreet() + ", " + c.getZip());

            } else {
                System.out.println("Kein Kunde angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Calls the method deactivate from FlightManagementImpl and passes a customer object
     * @param c The customer object, which will be deactivated
     */
    public void deleteCustomer(Customer c) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(c);

        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Edits an existing customer object by calling the method save from FlightManagementImpl and passes an customer object
     * @param firstName The edited firstname of the customer
     * @param lastName The edited lastname of the customer
     * @param street The edited street of the customer
     * @param zip The edited zip code of the customer
     * @param city The edited city of the customer
     * @param c The customer object, which is passed to the method save from FlightManagementImpl
     */
    public void updateCustomer(String firstName, String lastName, String street, String zip, String city, Customer c) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            c.setFirstname(firstName);
            c.setLastname(lastName);
            c.setStreet(street);
            c.setZip(Integer.valueOf(zip));
            c.setCity(city);

            management.save(c);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Gets all types from the management object
     * @return A vector containing types.
     */
    public Vector<Type> getAllTypes() {
        Vector v = new Vector();
        try {
            v = management.getAllTypes();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Gets all seats from the management object
     * @return A vector containing seats.
     */
    public Vector<Seat> getAllSeats() {
        Vector v = new Vector();
        try {
            v = management.getAllSeats();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Creates a new Type Object
     * @param name The name of the created type
     * @param rows The number of rows of the created type
     * @param columns The number of columns of the created type
     */
    public void createType(String name, String rows, String columns) {
        Type t = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            t = management.createType(name, Integer.valueOf(rows), Integer.valueOf(columns));

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (t != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neuer Type: " + "Type.-ID.: " + t.getTypeId() + ", " + t.getName() + ", " + t.getColumns() + ", " + t.getRows());

            } else {
                System.out.println("Kein Type angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
        //return airp;

    }

    /**
     * Creates a new Seat Object
     * @param row The row of the created seat inside of the plane
     * @param seat The seat of the created seat in the row inside of the plane
     * @param planeId Association to the plane object, in which the seat is inside of
     */
    public void createSeat(String row, String seat, int planeId) {
        Seat s = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            s = management.createSeat(Integer.valueOf(row), seat.charAt(0), planeId);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (s != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neuer Sitz: " + "Sitz.-ID.: " + s.getSeatId() + ", " + s.getRow() + ", " + s.getSeat() + ", " + s.getPlaneId());

            } else {
                System.out.println("Kein Sitz angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
        //return airp;

    }

    /**
     * Creates a new Flight Object
     * @param date The date of the created flight
     * @param planeId Association to the plane object, which accomplishes the flight
     * @param startAirportId The airport, where the flight starts
     * @param stopAirportId The airport, where the flight stops
     */
    public void createFlight(Date date, int planeId, int startAirportId, int stopAirportId) {
        Flight f = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            f = management.createFlight(date, planeId, startAirportId, stopAirportId);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (f != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neuer Flug: " + "Flug.-ID.: " + f.getFlightId() + ", " + f.getPlaneId() + ", " + f.getStartAirportId() + ", " + f.getDestAirportId());

            } else {
                System.out.println("Kein Flug angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
        //return airp;

    }

    /**
     * Returns a customer object by id
     * @param id The id of searched customer
     * @return The customer with index of <code>id</code>
     */
    public Customer findCustomerByKey(int id) {

        Customer c = null;
        try {

            c = management.getCustomerByKey(id);
            return c;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return c;
    }

    /**
     * Returns customer objects by lastname
     * @param lastName The lastname of searched customer(s)
     * @return The customer with lastname <code>lastName</code>
     */
    public Vector<Customer> findCustomerByLastName(String lastName) {

        Vector v = new Vector();
        try {
            v = management.getCustomerByLastName(lastName);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;

    }

    /**
     * Edits an existing type object by calling the method save from FlightManagementImpl and passes an type object
     * @param name The edited name of the type
     * @param rows The edited number of rows of the type
     * @param street The edited number of columns of the type
     * @param t The type object, which is edited and passed to the medhod save from FlightManagementImpl
     */
    public void updateType(String name, int rows, int columns, Type t) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            t.setName(name);
            t.setRows(rows);
            t.setColumns(columns);
            management.save(t);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Edits an existing seat object by calling the method save from FlightManagementImpl and passes an seat object
     * @param rows The edited row of the seat
     * @param street The edited column of the seat
     * @param t The seat object, which is edited and passed to the medhod save from FlightManagementImpl
     */
    public void updateSeat(String row, String seat, Seat s) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            s.setRow(Integer.valueOf(row));
            s.setSeat(seat.charAt(0));
            management.save(s);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Calls the method deactivate from FlightManagementImpl and passes a type object
     * @param t The type object, which will be deactivated
     */
    public void deleteType(Type t) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(t);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Returns a type object by id
     * @param id The id of searched type
     * @return The type with index of <code>id</code>
     */
    public Type findTypeByKey(int id) {
        Type t = null;
        try {

            t = management.findTypeByKey(id);
            return t;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return t;
    }

    /**
     * Returns type objects by name
     * @param name The name of searched type(s)
     * @return The type with name <code>name</code>
     */
    public Vector<Type> findTypeByName(String name) {
        Vector v = new Vector();
        try {
            v = management.findTypeByName(name);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns type objects by a quorum of seats inside of it
     * @param minSeats The quorum of seats
     * @return A vector containing types with a quorum of seats <code>minSeats<\code>
     */
    public Vector<Type> findTypeByMinSeatsTotal(int minSeats) {
        Vector v = new Vector();
        try {
            v = management.findTypeByMinSeatsTotal(minSeats);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns a seat object by id
     * @param id The id of searched seat
     * @return The seat with index of <code>id</code>
     */
    public Seat findSeatByKey(int id) {
        Seat s = null;
        try {

            s = management.findSeatByKey(id);
            return s;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return s;
    }

    /**
     * Returns seat objects, which are existing in a plane
     * @param p The plane object, which contains the searched seat(s)
     * @return A vector containing seats
     */
    public Vector<Seat> findSeatByPlane(Plane p) {
        Vector v = new Vector();
        try {
            v = management.findSeatByPlane(p);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns seat objects, which are existing in a plane
     * @param planeId The plane with index of <code>planeId</code>, which contains the searched seat(s)
     * @return A vector containing seats
     * @
     */
    public Vector<Seat> findSeatByPlane(int planeId) {
        Vector v = new Vector();
        try {
            v = management.findSeatByPlane(planeId);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns seat objects, which are involved in a flight
     * @param f The flight object, in which the seats are involved
     * @return A vector containing seats
     */
    public Vector<Seat> findBookedSeatByFlight(Flight f) {
        Vector v = new Vector();
        try {
            v = management.findBookedSeatByFlight(f);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns seat objects, which are involved in a flight
     * @param flighId The flight with index of <code>flightId</code>, in which the seats are involved
     * @return A vector containing seats
     */
    public Vector<Seat> findBookedSeatByFlight(int flightId) {
        Vector v = new Vector();
        try {
            v = management.findBookedSeatByFlight(flightId);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns a flight object by id
     * @param id The id of searched flight
     * @return The flight with index of <code>id</code>
     */
    public Flight findFlightByKey(int id) {
        Flight f = null;
        try {

            f = management.findFlightByKey(id);
            return f;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return f;
    }

    /**
     * Returns flight objects, which are accomplished by a plane
     * @param p The plane object, which accomplishes the flight
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByPlane(Plane p) {
        Vector v = new Vector();
        try {
            v = management.findFlightByPlane(p);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which are accomplished by a plane
     * @param planeId The plane with index of <code>planeId</code>, which accomplishes the flight
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByPlane(int planeId) {
        Vector v = new Vector();
        try {
            v = management.findFlightByPlane(planeId);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which are starting at an airport
     * @param a The airport object, where the searched flights are starting
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByStartAirport(Airport a) {
        Vector v = new Vector();
        try {
            v = management.findFlightByStartAirport(a);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which are starting at an airport
     * @param startAirportId The airport with index of <code>startAirportId</code>, where the searched flights are starting
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByStartAirport(int startAirportId) {
        Vector v = new Vector();
        try {
            v = management.findFlightByStartAirport(startAirportId);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which are destinating at an airport
     * @param a The airport object, where the searched flights are destinating
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByDestAirport(Airport a) {
        Vector v = new Vector();
        try {
            v = management.findFlightByDestAirport(a);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which are destinating at an airport
     * @param destAirportId The airport with index of <code>destAirportId</code>, where the searched flights are destinating
     * @return A vector containing flights  
     */
    public Vector<Flight> findFlightByDestAirport(int destAirportId) {
        Vector v = new Vector();
        try {
            v = management.findFlightByDestAirport(destAirportId);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, in which a customer is involved
     * @param c The customer object, who is involved in the flight
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByCustomer(Customer c) {
        Vector v = new Vector();
        try {
            v = management.findFlightByCustomer(c);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, in which a customer is involved
     * @param customerId The customer with index of <code>customerId</code>, who is involved in a flight
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByCustomer(int customerId) {
        Vector v = new Vector();
        try {
            v = management.findFlightByCustomer(customerId);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which is organized by an airline and in which a customer is involved
     * @param customerId The customer with index of <code>customerId</code>, who is involved in a flight
     * @param airlineId The airline with index of <code>airlineId</code>, which organizes a flight
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByCustomerAndAirline(int customerId, int airlineId) {
        Vector v = new Vector();
        try {
            v = management.findFlightByCustomerAndAirline(customerId, airlineId);

            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns flight objects, which is organized by an airline and in which a customer is involved
     * @param c The customer object, who is involved in a flight
     * @param a The airline object, which organizes a flight
     * @return A vector containing flights
     */
    public Vector<Flight> findFlightByCustomerAndAirline(Customer c, Airline a) throws RemoteException {
        Vector v = new Vector();
        try {
            v = management.findFlightByCustomerAndAirline(c, a);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Gets all airports from the management object
     * @return A vector containing airports.
     */
    public Vector<Airport> getAllAirports() {
        Vector v = new Vector();
        try {
            v = management.getAllAirports();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Creates a new Airport Object
     * @param name The name of the created airport
     * @param initials The initials of the created airport
     * @param city The city of the created airport
     */
    public void createAirport(String name, String initials, String city) {
        Airport airp = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            airp = management.createAirport(name, initials, city);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (airp != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neuer Airport: " + "Airport.-ID.: " + airp.getAirportId() + ", " + airp.getName() + ", " + airp.getInitials() + ", " + airp.getCity());

            } else {
                System.out.println("Kein Airport angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
        //return airp;
    }

    /**
     * Edits an existing airport object by calling the method save from FlightManagementImpl and passes an airport object
     * @param name The edited name of the airport
     * @param initials The edited initials of the airport
     * @param city The edited city of the airport
     * @param airp The airport object, which is edited and passed to the medhod save from FlightManagementImpl
     */
    public void updateAirport(String name, String initials, String city, Airport airp) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            airp.setName(name);
            airp.setInitials(initials);
            airp.setCity(city);
            management.save(airp);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }

    }

    /**
     * Calls the method deactivate from FlightManagementImpl and passes an airport object
     * @param airp The airport object, which will be deactivated
     */
    public void deleteAirport(Airport airp) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(airp);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Returns an airport object by id
     * @param id The id of searched airport
     * @return The airport with index of <code>id</code>
     */
    public Airport findAirportByKey(int id) {

        Airport a = null;
        try {

            a = management.findAirportByKey(id);
            return a;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return a;
    }

    /**
     * Returns airport objects by name
     * @param name The name of searched airport
     * @return The airport with name <code>name</code>
     */
    public Vector<Airport> findAirportByName(String name) {
        Vector v = new Vector();
        try {
            v = management.findAirportByName(name);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;

    }

    /**
     * Returns airport objects by initials
     * @param initials The initials of searched airport
     * @return The airport with name <code>initials</code>
     */
    public Vector<Airport> findAirportByInitials(String initials) {
        Vector v = new Vector();
        try {
            v = management.findAirportByInitials(initials);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;

    }

    /**
     * Returns airport objects by city
     * @param city The city of searched airport
     * @return The airport with city <code>city</code>
     */
    public Vector<Airport> findAirportByCity(String city) {
        Vector v = new Vector();
        try {
            v = management.findAirportByCity(city);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns airline objects by name
     * @param name The name of searched airport
     * @return The airport with name <code>name</code>
     */
    public Vector<Airline> findAirlineByName(String name) {
        Vector v = new Vector();
        try {
            v = management.findAirlineByName(name);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns airline objects by initials
     * @param initials The initials of searched airport
     * @return The airport with initials <code>initials</code>
     */
    public Vector<Airline> findAirlineByInitials(String initials) {
        Vector v = new Vector();
        try {
            v = management.findAirlineByInitials(initials);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Gets all planes from the management object
     * @return A vector containing planes.
     */
    public Vector<Plane> getAllPlanes() {

        Vector v = new Vector();
        try {
            v = management.getAllPlanes();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Creates a new Plane Object
     * @param name The name of the created plane
     * @param typeId Association to the type of the plane
     * @param airlineId Association to the airline, which operates the plane
     */
    public void createPlane(String name, int typeId, int airlineId) {
        Plane p = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            p = management.createPlane(typeId, airlineId, name);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (p != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neues Flugzeug: " + "Flugzeug.-ID.: " + p.getPlaneId() + ", " + p.getName() + ", " + p.getTypeId() + ", " + p.getAirlineId());

            } else {
                System.out.println("Kein Fugzeug angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
        //return airp;
    }

    /**
     * Edits an existing plane object by calling the method save from FlightManagementImpl and passes an plane object
     * @param name The edited name of the plane
     * @param typeId The edited type of the plane
     * @param city The edited airline, which operates the plane
     * @param p The plane object, which is edited and passed to the medhod save from FlightManagementImpl
     */
    public void updatePlane(String name, int typeId, int airlineId, Plane p) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            p.setName(name);
            p.setAirlineId(airlineId);
            p.setTypeId(typeId);
            management.save(p);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }

    }

    /**
     * Calls the method deactivate from FlightManagementImpl and passes a plane object
     * @param p The plane object, which will be deactivated
     */
    public void deletePlane(Plane p) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(p);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Returns Plane objects by id
     * @param id The id of searched Plane
     * @return The Plane with index <code>id</code>
     */
    public Plane findPlaneByKey(int id) {

        Plane p = null;
        try {

            p = management.findPlaneByKey(id);
            return p;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return p;
    }

    /**
     * Returns Plane objects by name
     * @param name The name of searched Plane
     * @return The Plane with name <code>name</code>
     */
    public Vector<Plane> findPlaneByName(String name) {
        Vector v = new Vector();
        try {
            v = management.findPlaneByName(name);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;

    }

    /**
     * Returns Plane objects by Type
     * @param Type The Type of searched Plane
     * @return The Planet with Type <code>Type</code>
     */
    public Vector<Plane> findPlaneByType(Type t) {
        Vector v = new Vector();
        try {
            v = management.findPlaneByType(t);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;

    }

    public Vector<Plane> findPlaneByAirline(Airline a) {
        Vector v = new Vector();
        try {
            v = management.findPlaneByAirline(a);
            return v;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;

    }

    /**
     * Gets all airlines from the management object
     * @return A vector containing airlines.
     */
    public Vector<Airline> getAllAirlines() {
        Vector v = new Vector();
        try {
            v = management.getAllAirlines();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Returns an airline objects by id
     * @param id The id of searched airline
     * @return The airline with index <code>id</code>
     */
    public Airline findAirlineByKey(int id) {
        Airline a = null;
        try {

            a = management.findAirlineByKey(id);
            return a;
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return a;

    }

    /**
     * Creating a new airline object
     * @param name The name of the created airline
     * @param initials The initials of the created airline
     */
    public void createAirline(String name, String initials) {
        Airline airl = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            airl = management.createAirline(name, initials);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (airl != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neue Airline: " + "Airline.-ID.: " + airl.getAirlineId() + ", " + airl.getName() + ", " + airl.getInitials());

            } else {
                System.out.println("Keine Airline angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
        //return airp;

    }

    /**
     * Edits an existing airline object by calling the method save from FlightManagementImpl and passes an airline object
     * @param name The edited name of the airline
     * @param initials The edited initials of the airline
     * @param airl The airline object, which is edited and passed to the medhod save from FlightManagementImpl
     */
    public void updateAirline(String name, String initials, Airline airl) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            airl.setName(name);
            airl.setInitials(initials);
            management.save(airl);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Edits an existing flight object by calling the method save from FlightManagementImpl and passes an flight object
     * @param date The edited date of the flight
     * @param plane Changing the plane, which accomplishes the flight
     * @param startAirportId Changing the airport, where the flight starts
     * @param destAirportId Changing the airport, where the flight stops
     * @param f The flight object, which is edited and passed to the medhod save from FlightManagementImpl
     */
    public void updateFlight(Date date, int planeId, int startAirportId, int destAirportId, Flight f) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            f.setDateTime(date);
            f.setPlaneId(planeId);
            f.setStartAirportId(startAirportId);
            f.setDestAirportId(destAirportId);

            management.save(f);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Calls the method deactivate from FlightManagementImpl and passes an airline object
     * @param airl The airline object, which will be deactivated
     */
    public void deleteAirline(Airline airl) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(airl);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    /**
     * Gets all flights from the management object
     * @return A vector containing flights.
     */
    public Vector<Flight> getAllFlights() {
        Vector v = new Vector();
        try {
            v = management.getAllFlights();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * Creates a new Flight Object
     * @param startAirportId The airport, where the flight starts
     * @param stopAirportId The airport, where the flight stops
     * @param date The date of the created flight
     * @param planeId Association to the plane object, which accomplishes the flight
     */
    void createFlight(int startAirportId, int destAirportId, Date date, int planeId) {
        Flight f = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            f = management.createFlight(date, planeId, startAirportId, destAirportId);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (f != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neuer Flug: " + "Airline.-ID.: " + f.getStartAirportId() + ", " + f.getDestAirportId() + ", " + f.getPlaneId());

            } else {
                System.out.println("Keine Airline angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    void deleteFlight(Flight f) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(f);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    void updateFlight(int startAirportId, int destAirportId, Date date, int planeId, Flight f) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            f.setDateTime(date);
            f.setPlaneId(planeId);
            f.setStartAirportId(startAirportId);
            f.setDestAirportId(destAirportId);

            management.save(f);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    public Vector<Booking> getAllBookings() {

        Vector<Booking> v = new Vector();
        try {
            v = management.getAllBookings();
        } catch (RemoteException ex) {
            Logger.getLogger(EBInterfaceClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    void createBooking(Date dateTime, int customerId, int flightId, int seatId) {

        Booking b = null;

        if (management == null) {
            initServerConnection(hostname);
        }
        // Die Bankverwaltung bitten wir, einen neuen Kunden anzulegen.
        try {
            b = management.createBooking(dateTime, customerId, flightId, seatId);

            /*
             * Wenn es darauf hin eine solchen Kunden gibt (daran zu erkenn,
             * dass c nicht leer ist), dann lesen wir nun einige Informationen
             * über den Kunden aus und setzen das ID-Feld.
             */
            if (b != null) {
                // Einfache Ausgabe der Daten des neuen Kundenobjekts
                System.out.println("Neue Buchung: " + "Customer ID: " + customerId + ", Flight ID: " + flightId);

            } else {
                System.out.println("Keine Buchung angelegt bzw. verfügbar.");
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }

    }

    void updateBooking(Date bookingDate, int customerId, int flightId, int seatId, Booking b) {
        if (management == null) {
            initServerConnection(hostname);
        }
        try {
            b.setCustomerId(customerId);
            b.setDateTime(bookingDate);
            b.setFlightId(flightId);
            b.setSeatId(seatId);

            management.save(b);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    void deleteBooking(Booking b){
          if (management == null) {
            initServerConnection(hostname);
        }
        try {
            management.deactivate(b);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }

    void checkInBooking(Booking b) {
         if (management == null) {
            initServerConnection(hostname);
        }
        try {
           b.setIsCheckedIn(true);
            b.setCheckedInDateTime(new Date());
            management.save(b);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);

        }
    }
}
